package com.designpattern.behavior.responsibility;

/**
 * @author Administration
 * @date 2021/10/21 - 16:10 - 星期四
 * @project 行为模式中的责任链模式 抽象处理者
 * @package com.designpattern.behavior.responsibility
 * @by 晨
 */
public abstract class Handler {

    protected final static Integer NUM_ONE = 1;

    protected final static Integer NUM_THREE = 3;

    protected final static Integer NUM_SEVEN = 7;

    //该领导处理的请假天数区间
    private Integer numStart;
    private Integer numEnd;

    //领导上面还有领导
    private Handler nextHandler;

    // 设置上级领导
    public void setNextHandler(Handler nextHandler) {
        this.nextHandler = nextHandler;
    }

    //设置请假天数范围 上不封顶
    public Handler(int numStart) {
        this.numStart = numStart;
    }

    //设置请假天数范围
    public Handler(int numStart, int numEnd) {
        this.numStart = numStart;
        this.numEnd = numEnd;
    }

    //各级领导处理请假条方法
    protected abstract void handleLeave(LeaveRequest leave);

    //提交请假条
    public final void submit(LeaveRequest leaveRequest) {
        // 该领导进行审批
        this.handleLeave(leaveRequest);

        if (this.nextHandler != null && leaveRequest.getNum() > numEnd) {
            // 提交上级审批
            this.nextHandler.submit(leaveRequest);
        } else {
            System.out.println("流程结束");
        }
    }
}
